/**
 * 项目详情页面：展示项目中的任务和项目日志等信息
 */

$(function(){
var urlroot = window.urlroot;
var _taskListView, _gridView;
var queryTaskUrl = urlroot + '/task/doQueryTaskList'; //查询任务路径
var queryChildTaskUrl = urlroot + '/task/doQueryChildTask'; //查询任务路径
var addTaskUrl = urlroot + '/task/doAddTask'; //添加任务路径
var divideTaskUrl = urlroot + '/task/doDivideTask'; //分解任务路径
var delTaskUrl = urlroot + '/task/doDelTask'; //删除任务路径
var countTaskUrl = urlroot + '/task/taskSatistic'; //统计任务路径
var taskDetUrl = urlroot + '/task/taskDtl'; //任务详情路径
var saveFileUrl = urlroot + '/comm/file/uploadFile'; //提交文档路径
var updateTaskProgressUrl = urlroot + '/task/doAddLogProgress'; //更新完成度请求路径
var delFileUrl = urlroot + '/comm/file/deleteFile'; //删除文档路径
var downFileUrl = urlroot + '/comm/file/downloadFile'; //下载文档路径
var taskTreeUrl = urlroot + '/task/doQueryTaskTree'; //任务子母视图数据请求路径
var doJudgeUrl = urlroot + '/task/doJudgePrivililedge'; //权限请求路径
var projectDetailListUrl = urlroot + '/project/projectDetailList'; //项目详情列表请求路径
var taskDetailUrl = urlroot + '/task/taskDetail'; //任务详情路径
var editProjectUrl = urlroot + '/project/projectDtl'; //编辑项目路径
var updateProjectUrl = urlroot + '/project/doUpdateProject'; //更新项目路径
var delProjectFileUrl = urlroot + '/project/doDelProjectFile'; //删除项目文档路径(已关联项目)
var projectDetailUrl = urlroot + '/project/projectDetail'; //项目详情请求路径
var doCloseTaskUrl = urlroot + '/task/doCloseTask'; //关闭任务路径
var doReOpenTaskUrl = urlroot + '/task/doReOpenTask'; //关闭任务路径
var doCloseProjectUrl = urlroot + '/project/doCloseProject'; //关闭项目
var doCancelProjectUrl = urlroot + '/project/doCancelProject'; //取消项目
var doQueryTaskTreePageUrl = urlroot + '/task/doQueryTaskTreePage'; //任务树形数据请求路径
var doUpdateStageUrl = urlroot + '/project/doUpdateStage';
var pmsBugAddUrl = urlroot + '/pmsBug/pmsBugAdd';

var taskOperatePowerKey = false;//权限标示
var addTaskTip = new HZBank.app.tip();
var taskCountTip = new HZBank.app.tip();
var progressTip = new HZBank.app.tip();
var editProjectTip = new HZBank.app.tip();
var progressTipConfig = {
		$element : '',
		content : $('#progressTip'), // 内容
		width : 250,
		height : 188,
		autohide : true,
		position : 'bottom',
		needbind : true // 自己绑定事件
}
var _check = new HZBank.app.formcheck();
var _checkConfig = {
		form :''
};
var controlNum = new HZBank.app.controlNum();
controlNum.init({
	el : 'input[name^=planTime]', 
	increment : 1,
	decimalsLength : 0,
	align : 'left',
	defaultValue : '',
	min :-9999999999999,
	needPaste : true
});
//分页
var isCreatePagination = false, pageSize = 20, pagination = $("#pagination");
//执行人模糊匹配添加
var executorInp = new HZBank.app.PowerTips().init({
	url :'operLucene',
	targetId : '#executorInp',
	width : '60px',
	clickCallBack : function(oper) {
		var operName = $('#executorInp').val();
		var operCode = oper;
		var spanStr = '<span class="executor-info" data-name="' + operName + '" data-code="' + operCode + '">' + operName + '<i>X</i>,</span>';
		var $curSpanObj = $('#executorBox').find('span.executor-info[data-code="' + operCode + '"]');
		if($curSpanObj.length == 0){
			$('#executorBox').append(spanStr);
		}else{
			$curSpanObj.addClass('exist-obj');
		}
		$('#executorInp').val('');
		$('#executorList').empty();
	}
});
//删除执行人
$('body').on('click','.executor-info i',function(e){
	e.stopPropagation();
	$(e.target).closest('span.executor-info').remove();
});
//显示隐藏添加执行人
$('#addExecutor').unbind('click').bind('click',function(){
	if($('#execPowBox').is(':visible')){
		$('#execPowBox').hide();
		$(this).text('+添加');
	}else{
		$('#execPowBox').show();
		$(this).text('-取消');
	}
});
//上传附件
$('#uploadFileBtn').unbind('click').bind('click',function(e) {
	var _this = this;
	var uploadConfig = {
		multiple : true,
		width: '700',
		uploadcallback : function(id, fileName, result) {
			var data = result.returnObject;
			if (data == null) {
				HZBank.showFail("出错了");
				return;
			}
			var files = data.result;
			var success = result.returnObject.success;
			if (!success) {
				HZBank.showFail(result.returnObject.message	|| result.exceptionMsg);
				return;
			}
			for (var i = 0; i < files.length; i++) {
				var data = files[i].uploadDate.split(' ');
				var d = data[0];
				$("#loanUploadMod ul").append('<li class="col1 ellipsis"><span class="file-name text-ell" title="'
										+ files[i].oriFileName
										+ '">'
										+ files[i].oriFileName
										+ '</span><a href="javascript:void(0);" class="delete_file float-right taskNewDelFile">删除</a>	<input type="hidden" name="fileName" value='
										+ files[i].fileName
										+ '></input><input '
										+ 'type="hidden" name="fileNum" value='
										+ files[i].fileSerialNo
										+ '></input></li>');
				$("#fileNo").val($("#fileNo").val() + files[i].fileSerialNo	+ ";");
			}
			/**
			 * 绑定删除文档事件
			 */
			$('.taskNewDelFile').unbind('click').bind('click', function(e) {
				e.stopPropagation();
				var _this = this;
				var fileSerialNo = $(e.target).closest("li").find("input[name='fileNum']").val();
				HZBank.ajaxJSON({
							url : delFileUrl,
							data : JSON.stringify({
										'fileSerialNo' : fileSerialNo
									}),
							success : function(result) {
								$("#fileNo").val($("#fileNo").val().replace(fileSerialNo + ";", ""));
								// 删除已上传文件节点
								$(e.target).closest("li").remove();
								HZBank.showMsg("删除成功！");
								HZBank.Utils.formmask('remove', $(e.target));
							}
						});
			});
		},
		el : $("#uploadFileBtn")
	};
	HZBank.showUpload(saveFileUrl,	uploadConfig);
});

var tipConfig = {
		$element : '',
		title : '新建任务',
		type : 'dialog', // 弹出类型， 'tip','dialog'
		customClass : 'blue-dialog',
		content : $('#addTaskTip'), // 内容
		width : 650,
		height : 450,
		animate : 'normal', 
		needbind : true, // 自己绑定事件
		needscroll : true, // tip的内容需不需要自带滚动条
		closeButton : true,
		needmask: true,
		buttons : {
				'创建任务' : function(){
					_gridView.addTask();
					
				},
				'取 消'    : function(e,that){
					that.close();
				}
		},
		buttonClass : ['btn-blue','btn-gray'],
		callback : function() { // 点击右上角关闭按钮的回调函数
			
		},
		endcallback : function() {
			$('#addTaskTip').find('select[name="projectNo"]').closest('li').show().end().select('enable');
			
		}
	}
var resolveTipConfig = {
		$element : '',
		title : '分解任务',
		type : 'dialog', // 弹出类型， 'tip','dialog'
		customClass : 'blue-dialog',
		content : $('#addTaskTip'), // 内容
		width : 650,
		height : 450,
		animate : 'normal', 
		needbind : true, // 自己绑定事件
		needscroll : true, // tip的内容需不需要自带滚动条
		closeButton : true,
		needmask: true,
		buttons : {
			'分解任务' : function(btn){
				var btnText = $(btn).text();
				_gridView.addTask(btnText);
				
			},
			'取 消'    : function(e,that){
				that.close();
			}
		},
		buttonClass : ['btn-blue','btn-gray'],
		callback : function() { // 点击右上角关闭按钮的回调函数
			
		},
		endcallback : function() {
			$('#addTaskTip').find('select[name="projectNo"]').closest('li').hide().end().select('disable');
		}
}
var taskCountConfig = {
		$element : '',
		title : '任务统计',
		type : 'dialog', // 弹出类型， 'tip','dialog'
		customClass : 'blue-dialog',
		content : $('#taskCount'), // 内容
		width : 600,
		height : 400,
		animate : 'normal', 
		needbind : true, // 自己绑定事件
		needscroll : true, // tip的内容需不需要自带滚动条
		closeButton : true,
		needmask: true,
	}
/*---------------------------配置start-------------------------------------*/	
//模糊匹配参数
var _ptConfigProj = {
		url :'operLucene',
		targetId : '',
		width : '160px',
		isGetOper : true,
		isLimitAuth : true,
		maxHeight : '150',
		chooseParent : false, // 是否允许选择上级机构
		viewModel : false,
		clickCallBack : function(oper) {
		}
	};
//tip基础参数配置
var tipConfigProject = {
		$element : '',
		title : '',
		type : 'dialog', // 弹出类型， 'tip','dialog'
		customClass : 'blue-dialog',
		content : $('#createTipBox'), // 内容
		width : 650,
		height : 700,
		animate : 'normal', 
		needbind : true, // 自己绑定事件
		needscroll : true, // tip的内容需不需要自带滚动条
		closeButton : true,
		needmask: true,
		buttonClass : ['btn-blue','btn-gray'],
		callback : function() { // 点击右上角关闭按钮的回调函数
			
		}
	}
/**
 * 项目成员相关操作
 */
var executorInpPj = new HZBank.app.PowerTips().init({
	url :'operLucene',
	targetId : '#executorInpPj',
	width : '60px',
	maxHeight : '150',
	clickCallBack : function(oper) {
		var operName = $('#executorInpPj').val();
		var operCode = oper;
		var spanStr = '<span class="executor-info" data-name="' + operName + '" data-code="' + operCode + '">' + operName + '<i>X</i>,</span>';
		var $curSpanObj = $('#executorBoxPj').find('span.executor-info[data-code="' + operCode + '"]');
		if($curSpanObj.length == 0){
			$('#executorBoxPj').append(spanStr);
		}else{
			$curSpanObj.addClass('exist-obj');
		}
		$('#executorInpPj').val('');
		$('#executorListPj').empty();
	}
});
//删除执行人
$('body').on('click','.executor-info i',function(e){
	e.stopPropagation();
	$(e.target).closest('span.executor-info').remove();
});
//显示隐藏添加执行人
$('#addExecutorPj').unbind('click').bind('click',function(){
	if($('#execPowBoxPj').is(':visible')){
		$('#execPowBoxPj').hide();
		$(this).text('+添加');
	}else{
		$('#execPowBoxPj').show();
		$(this).text('-取消');
	}
});
/**
 * 所属产品选择
 */
var executorInpPjPdQuery = new HZBank.app.PowerTips().init({
	url : 'productLucene',
	targetId : '#executorInpPjPdQuery',
	treeId : '#productTreeQuery',
	maxHeight : '150',
	chooseParent : true,
	width : '160px',
	isLimitAuth : true,
	clickCallBack : function(oper) {

	}
});
/**
 * 关联产品相关操作
 */
var executorInpPjPd = new HZBank.app.PowerTips().init({
	url : 'productLucene',
	targetId : '#executorInpPjPd',
	treeId : '#productTree',
	maxHeight : '150',
	chooseParent : true,
	width : '160px',
	isLimitAuth : true,
	clickCallBack : function(oper) {
		var prodName = $('#executorInpPjPd').val();
		var prodCode = oper;
		var spanStr = '<span class="executor-info" data-name="' + prodName + '" data-code="' + prodCode + '">' + prodName + '<i>X</i>,</span>';
		var $curSpanObj = $('#executorBoxPjPd').find('span.executor-info[data-code="' + prodCode + '"]');
		if($curSpanObj.length == 0){
			$('#executorBoxPjPd').append(spanStr);
		}else{
			$curSpanObj.addClass('exist-obj');
		}
		$('#executorInpPjPd').val('');
		$('#executorListPjPd').empty();
	}
});
//删除关联的产品
$('body').on('click','.executor-info i',function(e){
	e.stopPropagation();
	$(e.target).closest('span.executor-info').remove();
});
//显示隐藏管理产品
$('#addExecutorPjPd').unbind('click').bind('click',function(){
	if($('#execPowBoxPjPd').is(':visible')){
		$('#execPowBoxPjPd').hide();
		$(this).text('+关联');
	}else{
		$('#execPowBoxPjPd').show();
		$(this).text('-取消');
	}
});
/**
 * 项目文档相关操作
 */
$('#uploadFileBtnDoc').unbind('click').bind('click',function(e) {
	var _this = this;
	var uploadConfig = {
		multiple : true,
		uploadcallback : function(id, fileName, result) {
			var data = result.returnObject;
			if (data == null) {
				HZBank.showFail("出错了");
				return;
			}
			var files = data.result;
			var success = result.returnObject.success;
			if (!success) {
				HZBank.showFail(result.returnObject.message	|| result.exceptionMsg);
				return;
			}
			for (var i = 0; i < files.length; i++) {
				var data = files[i].uploadDate.split(' ');
				var d = data[0];
				$("#loanUploadModDoc ul").append('<li class="col1 ellipsis"><span class="file-name text-ell" title="'
										+ files[i].oriFileName
										+ '">'
										+ files[i].oriFileName
										+ '</span><a href="javascript:void(0);" class="delete_file float-right projectFileDel">删除</a>	<input type="hidden" name="fileName" value='
										+ files[i].fileName
										+ '></input><input '
										+ 'type="hidden" name="fileNum" value='
										+ files[i].fileSerialNo
										+ '></input></li>');
				$("#fileNo").val($("#fileNo").val() + files[i].fileSerialNo	+ ";");
			}
			/**
			 * 绑定新建项目时删除文档事件
			 */
			$('.projectFileDel').unbind('click').bind('click',function(e){
				e.stopPropagation();
				var _this = this;
				var fileSerialNo = $(e.target).closest("li").find("input[name='fileNum']").val();
				HZBank.ajaxJSON({
					url : delFileUrl,
					data : JSON.stringify({
								'fileSerialNo' : fileSerialNo
							}),
					success : function(result) {
						// 删除已上传文件节点
						$("#fileNo").val($("#fileNo").val().replace(fileSerialNo + ";", ""));
						$(e.target).closest("li").remove();
						HZBank.showMsg("删除成功！");
						HZBank.Utils.formmask('remove', $(e.target));
					}
				});
			});
		},
		el : $("#uploadFileBtnDoc")
	};
	HZBank.showUpload(saveFileUrl,	uploadConfig);
});
/*---------------------------配置end-------------------------------------*/
var taskListView = HZBank.View.Form.extend({
	el  : 'body',
	els : {
		'projectDetailList' : '#projectDetailList' //项目详情加载区域
	},
	events:{
		'click #editProjectBot' : 'editProjectAction', //编辑项目详情信息
		'click #closeProjectBot' : 'closeProjectBot', //关闭项目
		'click #cancelProjectBot' : 'cancelProjectBot', //取消项目
		'click #pauseProjectBot' : 'pauseProjectBot', //暂停项目
		'click #recoverProjectBot' : 'recoverProjectBot', //恢复项目
		'click .close-task' : 'closeTask', //关闭项目
		'click .open-task' : 'doReOpenTask', //重开项目
		'click #projTypeEdit  .ui-select-dropdown  li' : 'projTypeEdit', //重开项目
		'click #busiDepartEdit  .ui-select-dropdown  li label' : 'busiDepartEdit', //重开项目
		
				
		'click #addPmsBug' : 'addPmsBug' //统计任务
		//'click #taskCountBtn' : 'taskCount' //统计任务
	},
	addPmsBug:function(){
        var projectNo=$("#projectNo").val();
		window.open(pmsBugAddUrl+"?projectNo="+projectNo,"_blank");
	},
	projTypeEdit:function(e){
		console.log($(e.target).attr("data-val"));
		var projType=$(e.target).attr("data-val");
		if(projType=='5'||projType=='6'||projType=='7'){
			$("#busiDepartEdit select[name=busiDepart]").select("value",['XX']);
		}
	},
	busiDepartEdit:function(){
		var projType=$("#projTypeEdit select[name=projType]").val();
		if(projType=='5'||projType=='6'||projType=='7'){
			$("#busiDepartEdit select[name=busiDepart]").select("value",['XX']);
			HZBank.showWarn("硬件类、系统科、安全科项目的业主部门只能是信息技术部");
		}
	},
//	$("#projTypeEdit  .ui-select-dropdown  li").click(function(){
//		
//	});
//	$("#busiDepartEdit  .ui-select-dropdown  li label").click(function(e){
//		var projType=$("#projTypeEdit select[name=projType]").val();
//		if(projType=='5'||projType=='6'||projType=='7'){
//			$("#busiDepartEdit select[name=busiDepart]").select("value",['XX']);
//			HZBank.showWarn("硬件类、系统科、安全科项目的业主部门只能是信息技术部");
//		}
//	});
	/**
	 * 初始化
	 */
	init : function() {
		var _this = this;
		
		$("#projectTaskTab").on("click","a",function(){
			location.href=$(this).closest("li").attr("data-url")+'?projectNo='+$(this).attr("data-projectno");
		});
		
		$('#rateStatu a').unbind('click').bind('click',function(e){
			$('#rateStatu a.current').removeClass('current');
			$(this).addClass('current');
			_this.taskQuery ();
		});
		//勾选取消查看我的项目功能
		$('#myTask').unbind('click').bind('click',function(e){
			if($(this).is(':checked')){
				$('input[name="myTask"]').val('1');
			}else{
				$('input[name="myTask"]').val('');
			}
			_this.taskQuery ();
		});
		$('#tagNumBox button').unbind('click').bind('click',function(e){
			$('#tagNumBox button.btn-peculiar-green').removeClass('btn-peculiar-green');
			$(this).addClass('btn-peculiar-green');
			_this.taskQuery ();
		});
		//任务统计
		$('#taskCountBtn').unbind('click').bind('click',function(){
			_this.taskCount(_this);
		});
		var controlNum = new HZBank.app.controlNum();
		controlNum.init({
			el : 'input[name=hours]', 
			increment : 1,
			decimalsLength : 0,
			align : 'left',
			defaultValue : '',
			min :0
		});
	},
	initCallBack : function(){
		var _this = this;
		//获取隐藏域中选中的项目
		var selProjectNum = $('#selProjectNum').val();
		if(selProjectNum != ''){
//			$('#projectSelTask').select('value',selProjectNum);
//			$('#selProjectNum').attr('value','');
		}
		//获取当前项目权限
		_this.getPower($('#projectSelTask').val());
//		$('#projectSelTask').select('option',{
//			after : function(obj){
//				//获取选中项目权限
//				_this.getPower(obj.val);
//				_this.taskQuery ();
//				_this.loadProjectDetailList(obj.val);
//			}
//		});
		//项目
		new HZBank.app.PowerTips().init({
			url :'project',
			targetId : '#projectNameId',
			width : '160px',
			isGetOper : true,
			isLimitAuth : true,
			maxHeight : '150',
			chooseParent : false, // 是否允许选择上级机构
			viewModel : false,
			clickCallBack : function(oper) {
				console.log(oper);
				//获取选中项目权限
				_this.getPower(oper);
				_this.taskQuery ();
				_this.loadProjectDetailList(oper);
			}
		});
		_this.loadProjectDetailList($('#projectSelTask').val());
		_this.taskQuery ();
	},
	/**
	 * 加载项目详情相关列表
	 *  
	 */
	loadProjectDetailList : function(projectNo){
		var _this = this;
		$(_this.els.projectDetailList).mask('');
		var url = projectDetailListUrl + '?projectNo=' + projectNo;
		$(_this.els.projectDetailList).load(url,function(){
			$(_this.els.projectDetailList).unmask();
			var showDownload= $("#showDownload").val();
			if(showDownload){
				
			}else{
				$('#fj').find(".down-file-a").remove();
			}
		});
	},
	/**
	 * 关闭项目
	 *  
	 */
	closeTask : function(e){
		var _this = this;
		var _taskNo = $(e.target).closest('td').attr('data-taskno');
		HZBank.showConfim('是否关闭该任务？',function(){
			try{
				HZBank.ajaxJSON({
					url     : doCloseTaskUrl,
					data    : JSON.stringify({'taskNo' : _taskNo}),
					success : function(data){
						HZBank.showMsg('关闭成功');
						_this.taskQuery();
					}
				});
			}catch(e){
				alert('异步请求出错' + e.message);
			}
		},function(){
			
		});
		
	},
	doReOpenTask : function(e){
		var _this = this;
		var _taskNo = $(e.target).closest('td').attr('data-taskno');
		HZBank.showConfim('是否重开该任务？',function(){
			try{
				HZBank.ajaxJSON({
					url     : doReOpenTaskUrl,
					data    : JSON.stringify({'taskNo' : _taskNo}),
					success : function(data){
						HZBank.showMsg('重开成功');
						_this.taskQuery();
					}
				});
			}catch(e){
				alert('异步请求出错' + e.message);
			}
		},function(){
			
		});
		
	},
	/**
	 * 取消项目
	 *  
	 */
	cancelProjectBot : function(){
		var _this = this;
		var _projectNo = $('#listProjectId').text();
		HZBank.showConfim('是否取消该项目？',function(){
			try{
				HZBank.ajaxJSON({
					url     : doCancelProjectUrl,
					data    : JSON.stringify({'projectNo' : _projectNo}),
					success : function(data){
						HZBank.showMsg('取消成功');
						window.location.reload();
					}
				});
			}catch(e){
				alert('异步请求出错' + e.message);
			}
		},function(){
			
		});
	},
	/**
	 * 关闭项目
	 *  
	 */
	closeProjectBot : function(){
		var _this = this;
		var _projectNo = $('#listProjectId').text();
		HZBank.showConfim('是否关闭该项目？',function(){
			try{
				HZBank.ajaxJSON({
					url     : doCloseProjectUrl,
					data    : JSON.stringify({'projectNo' : _projectNo}),
					success : function(data){
						HZBank.showMsg('关闭成功');
						window.location.reload();
					}
				});
			}catch(e){
				alert('异步请求出错' + e.message);
			}
		},function(){
			
		});
	},
	/**
	 * 暂停项目
	 *  
	 */
	pauseProjectBot : function(){
		var _this = this;
		var _projectNo = $('#listProjectId').text();
		var url = urlroot + "/project/doPauseProject";
		HZBank.showConfim('是否暂停该项目？',function(){
			try{
				HZBank.ajaxJSON({
					url     : url,
					data    : JSON.stringify({'projectNo' : _projectNo}),
					success : function(data){
						HZBank.showMsg('暂停成功');
						window.location.reload();
					}
				});
			}catch(e){
				alert('异步请求出错' + e.message);
			}
		},function(){
			
		});
	},
	/**
	 * 恢复项目
	 *  
	 */
	recoverProjectBot : function(){
		var _this = this;
		var _projectNo = $('#listProjectId').text();
		var url = urlroot + "/project/doRecoverProject";
		HZBank.showConfim('是否恢复该项目？',function(){
			try{
				HZBank.ajaxJSON({
					url     : url,
					data    : JSON.stringify({'projectNo' : _projectNo}),
					success : function(data){
						HZBank.showMsg('恢复成功');
						window.location.reload();
					}
				});
			}catch(e){
				alert('异步请求出错' + e.message);
			}
		},function(){
			
		});
	},
	/**
	 * 获取权限
	 */
	getPower : function(projectNo){
		var _this = this;
		//改变头部标题
		$('#ptTitle').html('<span>'+$('#projectSelTask').attr('data-title')+'&nbsp;&nbsp;·&nbsp;&nbsp;</span><em>任务列表</em>');
		var _projectNo = projectNo;
		try{
			HZBank.ajaxJSON({
				type    : 'POST',
				url     : doJudgeUrl,
				data    : JSON.stringify({'projectNo' : _projectNo}),
				success : function(data){
					//改变权限标示
					console.log(data);
					taskOperatePowerKey = data.returnObject;
					console.log(taskOperatePowerKey);
					if(!taskOperatePowerKey){
						$('#addTask').addClass('btn-disable').attr('disabled','disabled');
					}else{
						$('#addTask').removeClass('btn-disable').removeAttr('disabled');
					}
				}
			});
		}catch(e){
			alert('异步请求出错' + e.message);
		}
	},
	/**
	 * 计算任务树高度
	 */
	countTaskTreeHeight : function(){
		var _this = this;
		var _winH = $(window).height();
		$('#taskTree').height(_winH - 300);
	},
	/**
	 * 任务筛选条件查询任务
	 */
	taskQuery : function(){
		var _this = this;
		_this.setStatuTag();
		var taskQueryData = HZBank.Utils.form2json('#taskQueryForm');
		console.log(taskQueryData);
		$("#projectTaskTab").find("a").attr("data-projectno",taskQueryData.projectNo);
		if(!_gridView){
			_gridView = new gridView();
		}
//		_gridView.refreshTable(taskQueryData);
		//渲染列表
		taskQueryData.taskLevel = '1';
		_gridView.initTable(taskQueryData,0);
	},
	/**
	 * 为进度状态和选中标签赋值
	 */
	setStatuTag : function(){
		var _this = this;
		var _rateStatuVal = $('#rateStatu li a.current').closest('li').data('value');
		var _tagNumVal = $('#tagNumBox li button.btn-peculiar-green').closest('li').data('value');
		$('input[name="doStatu"]').attr('value',_rateStatuVal);
		$('input[name="tagNum"]').attr('value',_tagNumVal);
	},
	/**
	 * 统计任务
	 */
	taskCount : function(_self){
		var _this = _self;
		var projectNo=$('#projectSelTask').val();
		try{
			HZBank.ajaxJSON({
				type    : 'POST',
				url     : countTaskUrl,
				data    : JSON.stringify({projectNo:projectNo}),
				success : function(data){
					_this.json2span (data.returnObject, '.task-count');
					taskCountTip.init(taskCountConfig);
				}
			});
		}catch(e){
			alert('异步请求出错' + e.message);
		}
		taskCountTip.init(taskCountConfig);
	},
	/**
	 * 任务统计返显
	 */
	json2span : function(json,area){
			var $area = $(area);
			var $cur;
			for (var key in json) {
				$cur = $area.find("[name='" + key + "']");
				if ($cur.is('span')) {
					$cur.text(json[key]);
				}
			}
	},
	/**
	 * 编辑请求:根据传入的项目编号获取项目信息，展示编辑窗口
	 */
	editProjectAction : function(){
		var _this = this;
		_this.curProjectNoData = $('#listProjectId').text();
		var obj = {'projectNo' : _this.curProjectNoData};
		try{
			$.ajax({
				type : 'POST',
				url  : editProjectUrl,
				data : obj,
				//contentType : 'application/json;charset=UTF-8',
				dataType : 'html',
				success : function(data){
					console.log(data);
					var isEdit=$(data).attr("hasRight");
					if(isEdit ==null){
						isEdit=false;
					}
					$('#editProjectBox').empty();
					$('#editProjectBox').append(data);
					var _editTipConfig = tipConfigProject;
					_editTipConfig.title = '编辑项目';
					_editTipConfig.content = $('#editProjectBox');
					if(isEdit){
						_editTipConfig.buttons = {
								'保存' : function(){
									//更新数据
									_this.updateProject();
									
								},
								'取 消' : function(e,that){
									that.close();
								}
						}
					}
					_editTipConfig.endcallback = function(that) {
						//编辑请求后执行
						_this.editProjectFun();
					}
					editProjectTip.init(_editTipConfig);
					
				}
			});
		}catch(e){
			alert('异步请求出错' + e.message);
		}
	},
	/**
	 * /编辑请求后执行:对弹出的编辑项目内容进行操作
	 */
	editProjectFun : function(){
		var _this = this;
		//初始化项目经理模糊匹配
		var _ptPmConfig = _ptConfigProj;
		_ptPmConfig.targetId = '#projManagerIdEdit';
		new HZBank.app.PowerTips().init(_ptPmConfig);
		//初始化技术经理模糊匹配
		var _ptTmConfig = _ptConfigProj;
		_ptTmConfig.targetId = '#techManagerIdEdit';
		new HZBank.app.PowerTips().init(_ptTmConfig);
		//下拉重新请求数据初始化表单
		$("select",'#editProjectForm').selectload();
		$('input[data-type="date"]').datetimepicker({
			pickTime : false,
			pickDate : true
		});
		//添加项目成员
		var executorInpPjOper = new HZBank.app.PowerTips().init({
			url :'operLucene',
			targetId : '#executorInpPjEdit',
			width : '60px',
			maxHeight : '150',
			clickCallBack : function(oper) {
				var operName = $('#executorInpPjEdit').val();
				var operCode = oper;
				var spanStr = '<span class="executor-info" data-name="' + operName + '" data-code="' + operCode + '">' + operName + '<i>X</i>,</span>';
				var $curSpanObj = $('#executorBoxPjEdit').find('span.executor-info[data-code="' + operCode + '"]');
				if($curSpanObj.length == 0){
					$('#executorBoxPjEdit').append(spanStr);
				}else{
					$curSpanObj.addClass('exist-obj');
				}
				$('#executorInpPjEdit').val('');
				$('#executorListPjEdit').empty();
			}
		});
		$('#addExecutorPjEdit').unbind('click').bind('click',function(e){
			if($('#execPowBoxPjEdit').is(':visible')){
				$('#execPowBoxPjEdit').hide();
				$(this).text('+添加');
			}else{
				$('#execPowBoxPjEdit').show();
				$(this).text('-取消');
			}
		});
		//关联产品
		var executorInpPjPdEdit = new HZBank.app.PowerTips().init({
			url : 'productLucene',
			targetId : '#executorInpPjPdEdit',
			treeId : '#productTreeEdit',
			maxHeight : '150',
			chooseParent : true,
			width : '160px',
			isLimitAuth : true,
			clickCallBack : function(oper) {
				var prodName = $('#executorInpPjPdEdit').val();
				var prodCode = oper;
				var spanStr = '<span class="executor-info" data-name="' + prodName + '" data-code="' + prodCode + '">' + prodName + '<i>X</i>,</span>';
				var $curSpanObj = $('#executorBoxPjPdEdit').find('span.executor-info[data-code="' + prodCode + '"]');
				if($curSpanObj.length == 0){
					$('#executorBoxPjPdEdit').append(spanStr);
				}else{
					$curSpanObj.addClass('exist-obj');
				}
				$('#executorInpPjPdEdit').val('');
				$('#executorListPjPdEdit').empty();
			}
		});
		$('#addExecutorPjPdEdit').unbind('click').bind('click',function(e){
			if($('#execPowBoxPjPdEdit').is(':visible')){
				$('#execPowBoxPjPdEdit').hide();
				$(this).text('+关联');
			}else{
				$('#execPowBoxPjPdEdit').show();
				$(this).text('-取消');
			}
		});
		/**
		 * 项目文档相关操作：编辑-上传
		 */
		$('#uploadFileBtnDocEdit').unbind('click').bind('click',function(e) {
			var _this = this;
			var uploadConfig = {
				multiple : true,
				uploadcallback : function(id, fileName, result) {
					var data = result.returnObject;
					if (data == null) {
						HZBank.showFail("出错了");
						return;
					}
					var files = data.result;
					var success = result.returnObject.success;
					if (!success) {
						HZBank.showFail(result.returnObject.message	|| result.exceptionMsg);
						return;
					}
					for (var i = 0; i < files.length; i++) {
						var data = files[i].uploadDate.split(' ');
						var d = data[0];
						$("#loanUploadModDocEdit ul").append('<li class="col1 ellipsis newFile"><span class="file-name text-ell" title="'
												+ files[i].oriFileName
												+ '">'
												+ files[i].oriFileName
												+ '</span><a href="javascript:void(0);" class="delete_file float-right projectFileDel-edit">删除</a>	<input type="hidden" name="fileName" value='
												+ files[i].fileName
												+ '></input><input '
												+ 'type="hidden" name="fileNum" value='
												+ files[i].fileSerialNo
												+ '></input></li>');
						$("#fileNoEdit").val($("#fileNoEdit").val() + files[i].fileSerialNo	+ ";");
					}
					
				},
				el : $("#uploadFileBtnDocEdit")
			};
			HZBank.showUpload(saveFileUrl,	uploadConfig);
		});
		/**
		 * 绑定编辑项目时删除文档事件-新添加的
		 */
		
		$('#loanUploadModDocEdit').on('click','.projectFileDel-edit',function(e){
			console.log('删除操作');
			var _this = this;
			var fileSerialNo = $(e.target).closest("li").find("input[name='fileNum']").val();
			var $curLi = $(e.target).closest('li');
			if($curLi.hasClass('newFile')){
				//新添加的
				var _requestUrl = delFileUrl;
				var _postData = {'fileSerialNo' : fileSerialNo};
			}else{
				//原有的
				var _requestUrl = delProjectFileUrl;
				var _postData = {'fileSerialNo' : fileSerialNo, 'projectNo' : $('#editProjectNo').val()};
			}
			HZBank.ajaxJSON({
				url : _requestUrl,
				data : JSON.stringify(_postData),
				success : function(result) {
					// 删除已上传文件节点
					if($curLi.hasClass('newFile')){
						$("#fileNoEdit").val($("#fileNoEdit").val().replace(fileSerialNo + ";", ""));
					}
					$(e.target).closest("li").remove();
					HZBank.showMsg("删除成功！");
					HZBank.Utils.formmask('remove', $(e.target));
				}
			});
		});
		/**
		 * 编辑文档下载功能
		 */
		$('.projectEditDownFile').unbind('click').bind('click', function(e) {
			e.stopPropagation();
			var fileSerialNo = $(e.target).closest("li").find("input[name='fileNum']").val();
			window.open(downFileUrl + "?fileSerialNo=" + fileSerialNo);
		});
		//_this.initKinEditor();
	},
	/**
	 * 更新项目：通过tip弹出框编辑项目信息，保存更新项目信息
	 */
	updateProject : function(){
		var _this = this;
		//表单验证
		_checkConfig.form = $('#editProjectForm');
		if(!_check.init(_checkConfig)){
			return;
		}
		//收集表单数据
		var _formData = HZBank.Utils.form2json('#editProjectForm');
		var beginDate=_formData.beginDate;
		var endDate=_formData.endDate;
		var planUpdateDate=_formData.planUpdateDate;
		var realUpdateDate=_formData.realUpdateDate;
		if(planUpdateDate){
			var flag=HZBank.Utils.dateCompare(beginDate, planUpdateDate);
			var flag2=HZBank.Utils.dateCompare(endDate, planUpdateDate);
			if(flag>0||flag2<0){
				HZBank.showFail('计划上线时间必须在项目开始日期和项目截至日期之间！');
				return;
			}
		}
		if(realUpdateDate){
			var flag=HZBank.Utils.dateCompare(beginDate, realUpdateDate);
			var flag2=HZBank.Utils.dateCompare(endDate, realUpdateDate);
			if(flag>0||flag2<0){
				HZBank.showFail('实际上线时间必须在项目开始日期和项目截至日期之间！');
				return;
			}
		}
		
		//项目成员特殊处理
//		if($('#executorBoxPjEdit span.executor-info').length == 0){
//			HZBank.showFail('项目成员不能为空！');
//			return;
//		}
	
		//关联产品特殊处理
		if($('#executorBoxPjPdEdit span.executor-info').length == 0){
			HZBank.showFail('关联产品不能为空！');
			return;
		}
		var _operList = [];
		//收集项目成员数据
		var $execuInfoSpan = $('.executor-info','#executorBoxPjEdit');
		if($execuInfoSpan.length > 0){
			var _length = $execuInfoSpan.length;
			for(var i = 0; i<_length; i++){
				var curSpan = $execuInfoSpan[i];
				_operList.push({"operNo" : $(curSpan).attr('data-code')});
			}
		}
		_formData.operList = _operList;
		//收集关联产品数据
		var _productList = [];
		var $execuInfoSpanPd = $('.executor-info','#executorBoxPjPdEdit');
		if($execuInfoSpanPd.length > 0){
			var _length = $execuInfoSpanPd.length;
			for(var i = 0; i<_length; i++){
				var curSpan = $execuInfoSpanPd[i];
				_productList.push({"productCode" : $(curSpan).attr('data-code')});
			}
		}
		_formData.productList = _productList;
		//业主部门特殊处理
		if(typeof(_formData.busiDepart) == 'string'){
			_formData.busiDepart = _formData.busiDepart.split();
		}
		_formData.busiDepart = _formData.busiDepart.join(',');
		//项目附件信息
		_formData.fileNo = $("#fileNoEdit").val();
		delete _formData.fileNum;
		delete _formData.fileName;
		try{
			HZBank.ajaxJSON({
				type        : 'POST',
				url         : updateProjectUrl,
				data        : JSON.stringify(_formData),
				dataType    : 'json',
				contentType : 'application/json;charset=UTF-8',
				success     : function(data){
					console.log('更新请求');
					if(data.successed){
						HZBank.showSuccess('更新成功！',function(){
							editProjectTip.close();
							window.open(projectDetailUrl + '?projectNo=' + _this.curProjectNoData, '_self');
						});
					}else{_this.curProjectNoData
						HZBank.showFail('更新失败！',function(){
							editProjectTip.close();
						});
					}
				}
			});
		}catch(e){
			alert('异步请求出错' + e.message);
		}
	}
});
/**
 * 任务列表展示视图
 */
var gridView = HZBank.View.Base.extend({
	el : '#gridTaskBox',
	els : {
		'dataTableMod' : '#dataTableMod',// 数据表格
		'taskTbody'    : '#taskTbody'// 任务表格tbody
	},
	events : {
		'click #addTask' : 'addTaskTip', // 创建任务
		'click #delTask' : 'delTask', // 删除任务
		'click #resolveTask' : 'resolveTask', // 分解任务
//		'click .show-task-detail' : 'showTask', // 展示任务详细信息
		'click .edit-progress' : 'editProgress', // 完成进度编辑
		'click #projStage' : 'projStage'
	},
	init : function() {
		var _this = this;
		_this.tableCtn = $(_this.els.dataTableMod).parent();
//		$(window).bind('click',function(e){
//			var $el = $(e.target);
//			if(!($el.is('#taskDetailArea *,#progressTip *'))){
//				_this.hideTaskDet();
//			}
//		});
		//取消进度
		$('body').on('click','#cancelProgress',function(){
			_this.cancelProgress ();
		});
		$('#progressHeader').unbind('click');
		$('body').on('click','#progressHeader',function(e){
			_this.editProgress(e);
		});
		//查询子任务方法
		$('.openCloseIcon').unbind('click')
		$('#taskDataBox').on('click','.openCloseIcon',function(e){
			var _curSpan = $(e.target).closest('span');
			var _curTr = _curSpan.closest('tr');
			if(_curSpan.hasClass('open-i')){
				_curSpan.find('i').text('+');
				_curSpan.removeClass('open-i');
				_curTr.next('tr.cur-tr-child').hide();
				_curTr.removeClass('cur-tr');
			}else{
				_curSpan.find('i').text('-');
				_curSpan.addClass('open-i');
				_curTr.next('tr.cur-tr-child').show();
				if(_curSpan.hasClass('oc-i-1')){
					_curTr.addClass('cur-tr');
				}
				var taskNo = _curSpan.attr('data-value');
				if(_curSpan.hasClass('close') ){
					_this.loadChildTask (_curSpan, taskNo);
					_curSpan.removeClass('close');
				}
				
			}
		});
		$('.allOpenClose').unbind('click').bind('click',function(e){
			var _curEl = $(e.target).closest('span');
			if(_curEl.hasClass('all-close')){
				_curEl.removeClass('all-close').addClass('all-open').text('合');
				$('.openCloseIcon i','#taskDataTable').text('-');
				$('tr','#taskDataTable').show().find('.openCloseIcon').addClass('open-i');
				$('span.close').each(function(i,el){
					var taskNo = $(el).attr('data-value');
					if(taskNo){
						_this.loadChildTask ($(el), taskNo);
					}
					$(el).removeClass('close');
				});
				
			}else if(_curEl.hasClass('all-open')){
				_curEl.removeClass('all-open').addClass('all-close').text('开');
				$('.openCloseIcon i','#taskDataTable').text('+');
				$('tr.cur-tr-child','#taskDataTable').hide();
				$('#taskDataTable').find('.openCloseIcon').removeClass('open-i');
				$('#taskDataTable').find('tr.cur-tr').removeClass('cur-tr');
				
			}
		});
	},
	initCallBack : function(){
		var _this = this;
	},
	/**
	 * 加载子任务 
	 */
	loadChildTask : function(el,taskNo){
		var _this = this;
		var _parentTrEl = $(el).closest('tr');
		var _taskNo = taskNo;
		var mytask=$("input[name='myTask']").val();
		try{
			HZBank.ajaxJSON({
				type    : 'POST',
				url     : queryChildTaskUrl,
				data    : JSON.stringify({'taskNo' : _taskNo,'mytask':mytask}),
				success : function(data){
					console.log(data);
//					var _returnObj = data.returnObject || {};
//					var taskDataSon = [{"taskNo":"1426761540171","taskName":"测试任务1","taskType":"01","taskLevel":1,"taskDesc":"阿萨德发生再制造","fatherTask":null,"preTask":null,"taskPriority":"01","taskOper":"123573","taskOperName":"许隽","projectNo":"proje333","beginDate":"2015-03-19","endDate":"2015-03-20","planTime":10,"realTime":10,"taskProgress":1.00,"testCaseNum":null,"passCaseNum":null,"runRate":null,"unrepairNum":null,"repairNumber":null,"repairRate":0.0,"regOper":"123573"},{"taskNo":"1426761540171","taskName":"测试任务1","taskType":"01","taskLevel":1,"taskDesc":"阿萨德发生再制造","fatherTask":null,"preTask":null,"taskPriority":"01","taskOper":"123573","taskOperName":"许隽","projectNo":"proje333","beginDate":"2015-03-19","endDate":"2015-03-20","planTime":10,"realTime":10,"taskProgress":1.00,"testCaseNum":null,"passCaseNum":null,"runRate":null,"unrepairNum":null,"repairNumber":null,"repairRate":0.0,"regOper":"123573"}];
					var taskDataSon = data.returnObject || [];
					if(taskDataSon.length > 0){
						var _sonTr = '<tr class="cur-tr-child" style="display: table-row;"><td colspan="10"><table>';
						for(var i=0; i<taskDataSon.length; i++){
							var _curData = taskDataSon[i];
							var _tr = _this.joinTaskTr(_curData);
							_sonTr+=_tr;
						}
						_sonTr+='</table></td></tr>';
						_parentTrEl.after($(_sonTr));
					}else{
						console.log('暂无数据！');
					}
				}
			});
		}catch(e){
			alert('异步请求出错' + e.message);
		}
	},
	/**
	 * 拼接任务信息 
	 * @param  data (json)
	 * @return _tr  (string);
	 */
	joinTaskTr : function(data){
		var _curData = data;
		//任务编号
		var _taskNo = _curData.taskNo;
		//任务名称
		var _taskName = _curData.taskName;
		//结束日期
		var _endDate = _curData.endDate;
		//执行人
		var _operListNameStr = _curData.operListNameStr || '';
		//级别
		var _outDateFlag = '';
		if(_curData.outDateFlag && _curData.state=='0'){
			_outDateFlag='<i title="过期" class="flag-circle-02"></i>';
		}else{
			_outDateFlag='<i title="正常" class="flag-circle-01"></i>' ;
		}
		//计划工时
		var _planTime = _curData.planTime || '';
		//已汇报工时
		var _realTime = _curData.realTime || '';
		//是否叶子节点
		var _isLeaf = _curData.isLeaf || '1';
		var _openClose = _isLeaf == '0' ? '<span class="openCloseIcon oc-i-1" data-value="'+_taskNo+'"><i>-</i></span>' : '<span></span>';
		if((( typeof(_curData.open)!='undefined' && !_curData.open)) && _isLeaf=='0'){
			_openClose ='<span class="openCloseIcon close" data-value="'+_taskNo+'"><i>+</i></span>';
		}else if(typeof(_curData.open)=='undefined' && _isLeaf=='0'){
			_openClose ='<span class="openCloseIcon close" data-value="'+_taskNo+'"><i>+</i></span>';
		}
		
		//完成度
		var _taskProgress = _curData.taskProgress || 0;
		var _progressStr = (_isLeaf == '1'&&_curData.state=='0') ? '<span class="edit-progress">'+_taskProgress+'%<i class="iconDeep icon-gray-down"></i></span>' : '<span>'+_taskProgress+'%</span>' 
		var _tr = '<tr>'
			+ '<td class="t1"><input type="checkbox" name="taskCheckbox" value="'+_taskNo+'" /></td>'
			+ '<td class="t2">'+_openClose+'</td>'
			+ '<td class="t3" title="' +_taskName+'"><span>'+_taskName+'</span></td>'
			+ '<td class="t4"><span>'+_endDate+'</span></td>'
			+ '<td class="t5"><span>'+_operListNameStr+'</span></td>'
			+ '<td class="t6"><span>'+_outDateFlag+'</span></td>'
			+ '<td class="t10"><span>'+_planTime+'</span></td>'
			+ '<td class="t9"><span>'+_realTime+'</span></td>'
			+ '<td class="t7" data-taskNo="'+_taskNo+'" data-value="'+_taskProgress+'">'+_progressStr+'</td>'
			+ '<td class="t8" data-taskNo="'+_taskNo+'"><span>'
			+ '<a class="show-task-detail" target="_blank" href="'+taskDetailUrl+'?taskNo='+_taskNo+'">详情</a>';
		if("1"!=data.state && data._search){
			_tr+= '<a class="close-task" href="javascript:void(0)">关闭</a>';
		}
		if("0"!=data.state && data._search){
			_tr+= '<a class="open-task" href="javascript:void(0)">重开</a>';
		}
			_tr+= '</span></td>'+'</tr>';
		return _tr;
	},
	/**
	 * 渲染数据表格 
	 */
	initTable : function(postData,currentPage){
		var _this = this;
		_this.defData = postData;
		var _currentPage = currentPage + 1;
		var _postData = postData;
		_postData.page = _currentPage+'';
		_postData.rows = pageSize+'';
		try{
			$.ajax({
				type    : 'POST',
//				url     : queryTaskUrl,
				url     : doQueryTaskTreePageUrl,
				data    : _postData,
				success : function(data){
					//渲染数据
					$(_this.els.taskTbody).empty();
					var taskTreeData = data.returnObject.content || [];
					if(taskTreeData.length > 0){
						for(var i=0; i<taskTreeData.length; i++){
							//获取当前数据
							var _curData = taskTreeData[i];
							//获取当前任务的详细信息
							var _curDataTask = _curData.taskDto;
							_curDataTask.open=_curData.open;
							//返回拼接的行任务数据
							var _tr = _this.joinTaskTr(_curDataTask);
							//加入页面中
							$(_this.els.taskTbody).append(_tr);
							//判断当前任务是否有子任务---------------------------------2级任务
							var _curTaskChild = _curData.children || [];
							if(_curTaskChild.length > 0){
								var _sonTrS = '<tr class="cur-tr-child"><td colspan="10"><table>';
								var _sonTrE = '</table></td></tr>';
								//2级子任务返回行
								var fullBackSon2 = '';
								var _backSonTr = '';
								//迭代子任务
								for(var j=0;j<_curTaskChild.length;j++){
									//获取当前子任务数据
									var _curSonData = _curTaskChild[j];
									//获取当前子任务详细信息
									var _curSonDataTask = _curSonData.taskDto;
									//返回拼接的行任务数据----------------------返回的二级任务行
									_curSonDataTask.open=_curSonData.open;
									_backSonTr = _this.joinTaskTr(_curSonDataTask);
									
									//判断当前任务是否有子任务---------------------------------3级任务
									var _curTaskChild3 = _curSonData.children || [];
									var fullTr3 = '';
									if(_curTaskChild3.length > 0){
										var _sonTr3S = '<tr class="cur-tr-child"><td colspan="10"><table>';
										var _sonTr3E = '</table></td></tr>';
										var _backSonTr3 = '';
										for(var k=0;k<_curTaskChild3.length;k++){
											//获取当前子任务数据
											var _curSonData3 = _curTaskChild3[k];
											//获取当前子任务详细信息
											var _curSonDataTask3 = _curSonData3.taskDto;
											_curSonDataTask3.open=_curSonData3.open;
											//返回拼接的行任务数据
											_backSonTr3 += _this.joinTaskTr(_curSonDataTask3);
										}
										fullTr3 = _sonTr3S + _backSonTr3 + _sonTr3E;
									}
									fullBackSon2 += _backSonTr + fullTr3;
								}
								$(_this.els.taskTbody).append(_sonTrS + fullBackSon2 + _sonTrE);
							}
						}
						//分页设置
						if(data.returnObject.total > 0 && !isCreatePagination){
							var opt = {};
							opt.current_page = currentPage;
							opt.items_per_page = pageSize;
							opt.callback = function(){_this.getPageStatus(_this)};
							pagination.pagination(data.returnObject.total, opt);
						}
						//默认展开
						var _curEl = $(".allOpenClose").closest('span');
						_curEl.removeClass('all-close').addClass('all-open').text('合');
						$('.openCloseIcon','#taskDataTable').not('.close').find('i').text('-');
						$('tr','#taskDataTable').show().find('.openCloseIcon').not('.close').addClass('open-i');
					}else{
						pagination.html('');
						//alert('暂无数据！');
						$('#taskTbody').append('<tr><td colspan="10" style="height:300px;line-height:300px;text-align:center;">暂无数据</td></tr>')
					}
				}
			});
		}catch(e){
			alert('异步请求出错' + e.message);
		}
	},
	/**
	 * 插入表数据
	 */
	insertTable : function(taskTrData,formData) {
		var taskPriorityStr = {'false':'正常','true':'过期'};
		var taskPriorityClass = {'false':'01','true':'02'};
		var operatorObj = {};
		$('#taskOperSelect option').each(function() {
			operatorObj[$(this).val()] = $(this).text();
		});
		var operatorObjStr = [];
		for(var i in formData.operList){
			operatorObjStr.push(operatorObj[formData.operList[i]]);
		}
		operatorObjStr = operatorObjStr.join(',');
		var trHtml = '';
		var editProgress = '<span>'+'0'+'%</span>';
		if(taskTrData.state=='0'){
			editProgress = '<span class="edit-progress">'+'0'+'%<i class="iconDeep icon-gray-down"></i></span>';
		}
		trHtml = '<tr>'
			+'<td class="t1">'
			+'<input type="checkbox" value="'+taskTrData.taskNo+'" name="taskCheckbox">'
			+'</td><td class="t2">'
			+'<span></span>'
			+'</td><td title="'+taskTrData.taskName+'" class="t3">'
			+'<span>'+taskTrData.taskName+'</span>'
			+'</td><td class="t4">'
			+'<span>'+formData.endDate+'</span>'
			+'</td><td class="t5">'
			+'<span>'+operatorObjStr+'</span>'
			+'</td><td class="t6">'
			+'<span><i class="flag-circle-'+taskPriorityClass[taskTrData.outDateFlag]+'" title="'+taskPriorityStr[taskTrData.outDateFlag]+'"></i></span>'
			+'</td><td class="t10">'
			+'<span>'+taskTrData.planTime+'</span>'
			+'</td><td class="t9">'
			+'<span></span>'
			+'</td><td data-value="'+'0'+'" data-taskno="'+taskTrData.taskNo+'" class="t7">'
			+editProgress
			+'</td><td data-taskno="'+taskTrData.taskNo+'" class="t8">'
			+'<span><a href="'+window.urlroot+'/task/taskDetail?taskNo='+taskTrData.taskNo+'" target="_blank" class="show-task-detail">详情</a><a href="javascript:void(0)" class="close-task">关闭</a></span>'
			+'</td></tr>';
		if(taskTrData.fatherTask && taskTrData.fatherTask != ''){
			//分解任务
			var $fatherTaskTr = $('#taskTbody').find('input[value='+taskTrData.fatherTask+']').closest('tr');
			if($fatherTaskTr.next('.cur-tr-child').length>0){
				
				$fatherTaskTr.next('.cur-tr-child').find('tbody').append(trHtml);
			}else {
				$fatherTaskTr.after('<tr class="cur-tr-child" style="display: table-row;"><td colspan="10"><table><tbody>'+trHtml+'</tbody></table></td></tr>');
			}
			if(!$fatherTaskTr.find('td.t2 span').hasClass('openCloseIcon')){
				$fatherTaskTr.find('td.t2').empty().append('<span data-value="'+taskTrData.fatherTask+'" class="openCloseIcon oc-i-1 open-i"><i>-</i></span>');
			}
		}else {
			//创建任务
			if($('#taskTbody tr').length =='1'&&$('#taskTbody tr').text()=='暂无数据'){
				$('#taskTbody').empty();
			}
			$('#taskTbody').append(trHtml);
		}
	},
	/**
	 * 获取分页条的当前页码，并根据页码数向后台请求成员列表数据 
	 */
	getPageStatus: function(self){
		var _this = self;
		var _currentPageStr = pagination.find(".current").text();
		//console.log('_currentPageStr' + _currentPageStr);
		var _currentPage = parseInt(_currentPageStr) - 1;
		console.log(_currentPage);
		_this.initTable(_this.defData,_currentPage);
	},
	/**
	 * 展示创建任务tip 
	 */
	addTaskTip : function(){
		var _this = this;
		if(!taskOperatePowerKey){
			return;
		}
		
		_this.loadProjectOper();
		
		addTaskTip.init(tipConfig);
		_this.clearForm ('#addTaskForm');
	},
	/**
	 * 添加任务
	 */
	addTask : function(btnText){
		var _this = this;
		var _btnText = btnText;
		//表单验证
		_checkConfig.form = $('#addTaskForm');
		if(!_check.init(_checkConfig)){
			return;
		}
		var $thisBtn = $('.tip-button-container').find('.tip-button').eq(0);
		if($thisBtn.hasClass('flag')){
			return;
		}
		$thisBtn.addClass('flag');
//		if($('#executorBox span.executor-info').length == 0){
//			HZBank.showFail('执行人不能为空！');
//			return;
//		}
		var _formData = HZBank.Utils.form2json('#addTaskForm');
//		var _operList = [];
		//收集执行人数据
//		var $execuInfoSpan = $('.executor-info','#executorBox');
//		if($execuInfoSpan.length > 0){
//			var _length = $execuInfoSpan.length;
//			for(var i = 0; i<_length; i++){
//				var curSpan = $execuInfoSpan[i];
//				_operList.push($(curSpan).attr('data-code'));
//			}
//			_formData.operList = _operList;
//		}
		if(typeof(_formData.operList) == 'string'){
			_formData.operList = [_formData.operList];
		}
		//任务附件信息
		_formData.fileNo = $("#fileNo").val();
		
		var projectNo =  $('#projectSelTask').val();
		if(!projectNo){
			HZBank.showWarn('请选择项目');
			$thisBtn.removeClass('flag');
			return ;
		}
		_formData.projectNo=projectNo;
		//定义请求路径
		var _taskRequestUrl = addTaskUrl;
		//判断是分解还是新建
		if(_btnText == '分解任务'){
			console.log(_this.selRowData);
			_formData.fatherTask = _this.selRowData;
			_formData.projectNo = $('#projectSelTask').val();
			_taskRequestUrl = divideTaskUrl;
		}
		delete _formData.fileNum;
		delete _formData.fileName;
		try{
			HZBank.ajaxJSON({
				type    : 'POST',
				url     : _taskRequestUrl,
				data    : JSON.stringify(_formData),
				success : function(data){
//					console.log(data);
					HZBank.showSuccess('创建成功！',function(){
						//关闭tip
						$thisBtn.removeClass('flag');
						addTaskTip.close();
						//根据筛选条件重新查询数据
						if(data&&data.returnObject){
							_this.insertTable(data.returnObject,_formData)
						}
//						_taskListView.taskQuery();
					});
				},
				failed:function(){
					$thisBtn.removeClass('flag');
				}
			});
		}catch(e){
			$thisBtn.removeClass('flag');
			alert('异步请求出错' + e.message);
		}
	},
	/**
	 * 重置表单
	 */
	clearForm : function(formObj){
		var _this = this;
			$('#executorBox').empty();
			$("#loanUploadMod ul").empty();
			$("#fileNo").val('');
			$('#execPowBox').hide();
			$('#addExecutor').text('+添加');
			$(formObj).find('input[type=text],textarea').val('');
			// reset checkbox
			$('input[type=checkbox]',formObj).checkbox('reset');
			// reset radiobutton
			$('input[type=radio]',formObj).radio('reset');
			// reset select
			$('select:not([multiple],[data-ignore="true"],[role="listbox"],[disabled])', formObj).select('reset');
	},
	/**
	 * 展示任务详细信息
	 */
	showTask : function(e){
		e.stopPropagation();
		var _this = this;
//		if($(e.target).is(':input')){
//			_this.hideTaskDet();
//			return;
//		}
		var _taskNo = $(e.target).attr('data-taskNo');
		var taskNumObj = {taskNo : _taskNo};
		_this.openTaskDet ();
		_this.loadTaskDet(taskNumObj);
	},
	/**
	 * 加载任务详细信息 
	 */
	loadTaskDet : function(taskNumJson){
		var _this = this;
		$('#taskDetailArea').empty();
		$('#taskDetailArea').mask('');
		try{
			$.ajax({
				type : 'POST',
				url : taskDetUrl,
				data : taskNumJson,
				dataType : 'html',
				success : function(data) {
					$('#taskDetailArea').append(data);
//					_this.openTaskDet ();
					$('#taskDetailArea').unmask('');
				},
				failed : function() {
					$('#taskDetailArea').unmask('');
				}
			});
		}catch(e){
			alert('异步请求出错' + e.message);
		}
		_this.openTaskDet ();
	},
	/**
	 * 展示任务详情 
	 */
	openTaskDet : function(){
		var _this = this;
		$('#taskDetailArea').show();
		$('#taskDetailArea').animate({
			right : '-2px',
		},300);
	},
	/**
	 * 隐藏任务详情 
	 */
	hideTaskDet : function(){
		var _this = this;
		$('#taskDetailArea').animate({
			right : '-500px',
		},300,function(){
			$('#taskDetailArea').hide();
		});
	},
	/**
	 * 分解任务：先判断是否选中行，然后根据选中行的具体数据对任务进行分解
	 */
	resolveTask : function(){
		var _this = this;
		var selectedData = _this.getSelectedRowsData();
		if (0 == selectedData.length || selectedData.length > 1) {
			HZBank.showFail('请选中一行！');
			return;
		}
		_this.selRowData = selectedData[0];
		console.log(selectedData[0])
		HZBank.ajaxJSON({
			type    : 'POST',
			url     : urlroot + "/task/checkTaskDivide?taskNo="+selectedData[0]+"&projectNo="+$('#projectSelTask').val(),
			success : function(data){
				_this.clearForm ('#addTaskForm');
				_this.loadProjectOper(_this.selRowData);
				addTaskTip.init(resolveTipConfig);
			},failed:function(){
				return ;
			}
		});
		
	},
	loadProjectOper:function( taskNo){
		var projectNo=$('#projectSelTask').val();
		var obj ={projectNo:projectNo};
//		if(typeof( taskNo)!='undefinde' && taskNo!=null){
			obj.taskNo=taskNo;
//		}
		HZBank.ajaxJSON({
			type    : 'POST',
			url     : urlroot + "/task/loadProjectOper",
			data    : JSON.stringify(obj),
			success : function(data){
				if(data && data.returnObject ){
					var option ='';
					var optionOther='';
					var operNo=$("#operNo").val();
					var optionBoolean=false;
					for(var i=0; i< data.returnObject.length ; i++){
						var op=data.returnObject[i];
						if(op.operCode==operNo){
							option +='<option value="' + op.operCode +'">' +op.operName +'</option>';
							optionBoolean=true;
						}else{
							optionOther +='<option value="' + op.operCode +'">' +op.operName +'</option>';
						}
					}
					option+=optionOther;
					$('#taskOperSelect').html(option);
					var opFirst = data.returnObject[0] || {};
					var opFirstCode = opFirst.operCode || '';
					console.log(opFirstCode);
					if(optionBoolean){
						$('#taskOperSelect').select('value',[operNo]);
					}else{
						$('#taskOperSelect').select('value',[opFirstCode]);
					}
					$('#taskOperSelect').select('refresh');
				}
			}
		});
	},
	/**
	 * 删除任务：先判断是否选中行，然后根据选中行的具体数据删除对应的数据
	 * 需要判断是表格视图还是出子母视图
	 */
	delTask : function(){
		var _this = this;
		var selectedData = _this.getSelectedRowsData();
		if (0 == selectedData.length) {
			HZBank.showFail('请选中行！');
			return;
		}
		HZBank.showConfim('是否确定要删除？', function() {
			var dataObj = {};
			dataObj['taskNoList'] = selectedData;
			_this.$el.mask('');
			console.log(dataObj);
			HZBank.ajaxJSON({
				url : delTaskUrl,
				data : JSON.stringify(dataObj),
				success : function(result) {
					HZBank.showMsg('删除成功！');
					_this.$el.unmask('');
					_taskListView.taskQuery();
				},
				failed : function() {
					_this.$el.unmask('');
				}
			});
		});
	},
	/**
	 * 编辑任务完成度：通过点击某个任务完成度弹出编辑任务完成度窗口
	 */
	editProgress : function(e) {
		var _this = this;
		var _curEl = $(e.target).closest('td');
		var _taskNo = _curEl.attr('data-taskNo');
		var _val = _curEl.attr('data-value');
		if(_val.indexOf('.') >= 0){
			var _pointIndex = _val.indexOf('.')
			_val = _val.substring(0,_pointIndex);
		}
		var _progressTipConfig = progressTipConfig;
		_progressTipConfig.$element = _curEl;
		_progressTipConfig.endcallback = function(){
			$('#progressTip select[name="taskProgress"]').select('value',_val);
			$('#progressTip input[name="taskNo"]').val(_taskNo);
			$('#progressTip .form-check-tip').remove();
			_check.formErrReset();
			//保存进度
			$('#saveProgress').unbind('click');
			$('#saveProgress').bind('click',function(){
				_this.saveProgress ();
			});
		};
		$('#progressTip textarea, #progressTip input[name="hours"]').val('');
		progressTip.init(_progressTipConfig);
	},
	/**
	 * 更新完成度
	 */
	saveProgress : function(e) {
		var _this = this;
		var _progressCheckConfig = _checkConfig;
		_progressCheckConfig.form = $('#progressTip form');
		if(!_check.init(_progressCheckConfig)){
			return;
		}
		var _postData = HZBank.Utils.form2json($('#progressTip form'));
		console.log(_postData);
		_this.$el.mask('');
		HZBank.ajaxJSON({
			url : updateTaskProgressUrl,
			data : JSON.stringify(_postData),
			success : function(result) {
				progressTip.close();
				HZBank.showMsg('更新成功！');
				//根据筛选条件重新查询数据
				_taskListView.taskQuery();
				_this.$el.unmask('');
			},
			failed:function(){
				_this.$el.unmask('');
			}
		});
	},
	//更新项目阶段
	projStage:function(){
		var _this = this;
		$("select[name=projStages]").select('option',{
			after: function(obj) {
				HZBank.showConfim('是否确定要更新项目阶段？', function() {
					var projectNo=$("#projectNo").val();
					HZBank.ajaxJSON({
						url : doUpdateStageUrl+"?projectNo="+projectNo+"&projStage="+obj.val,
	//					data : JSON.stringify(dataObj),
						success : function(result) {
							HZBank.showMsg('更新成功！');
							_this.$el.unmask('');
							_taskListView.taskQuery();
						},
						failed : function() {
							_this.$el.unmask('');
						}
					});
				});
			}
		});	
	},
	/**
	 * 取消进度编辑
	 */
	cancelProgress : function() {
		var _this = this;
		progressTip.close();
	},
	/**
	 * 获取选中行数据
	 */
	getSelectedRowsData : function() {
		_this = this;
		var data = [];
		$('#taskTbody').find('input[name="taskCheckbox"]:checked').each(function(index) {
			data.push($(this).val());
		});
		console.log(data);
		return data;
	}
	
});
_taskListView = new taskListView();

});